package com.kly.user.db.dao.impl;
import com.fqgj.common.base.AbstractBaseMapper;
import com.fqgj.common.utils.CollectionUtils;
import com.fqgj.common.utils.StringUtils;
import com.google.common.collect.Maps;
import com.kly.user.db.dao.UserConversationCustomerDao;
import com.kly.user.db.dao.UserConversationDao;
import com.kly.user.db.entity.UserConversationCustomerEntity;
import com.kly.user.db.entity.UserConversationEntity;
import com.kly.user.db.entity.UserModelEntity;
import com.kly.user.dto.chatter.request.ConversationOPReq;
import org.springframework.stereotype.Repository;

import java.util.Calendar;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
* User: linqu
* Date: 2023-06-08
* Time: 19:27:43.191
*/

@Repository
public class UserConversationCustomerDaoImpl extends AbstractBaseMapper<UserConversationCustomerEntity> implements UserConversationCustomerDao {
    /**
     * 加星标记
     */
    private static final Integer sessionSaveFlag = 1;

    @Override
    public List<UserConversationCustomerEntity> queryChatList(String chatterUserCode, String modelUserCode, Integer sessionSaveFlag, Integer pageNum, Integer pageSize) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("chatterUserCode", chatterUserCode);
        params.put("modelUserCode", modelUserCode);
        if (Objects.nonNull(sessionSaveFlag)) {
            params.put("sessionSaveFlag", sessionSaveFlag);
        }
        Calendar noMemberTime = Calendar.getInstance();//获取对日期操作的类对象
        noMemberTime.add(Calendar.DATE, -7);
        params.put("latestTime", noMemberTime.getTime());
        params.put("pageStart", (pageNum - 1) * pageSize);
        params.put("pageSize", pageSize);
        return this.getSqlSession().selectList(this.getStatement("queryChatList"), params);
    }

    @Override
    public List<UserConversationCustomerEntity> queryChatList(String chatterUserCode, String modelUserCode, String nickName, Integer sessionSaveFlag, Integer pageNum, Integer pageSize) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("chatterUserCode", chatterUserCode);
        params.put("modelUserCode", modelUserCode);
        if (Objects.nonNull(sessionSaveFlag)) {
            params.put("sessionSaveFlag", sessionSaveFlag);
        }
        if (StringUtils.isNotEmpty(nickName)) {
            params.put("nickName", nickName);
        }
        pageNum = pageNum == 0 ? 1 : pageNum;
        params.put("pageStart", (pageNum - 1) * pageSize);
        params.put("pageSize", pageSize);
        return this.getSqlSession().selectList(this.getStatement("queryChatList"), params);
    }

    @Override
    public List<UserConversationCustomerEntity> queryUnReadNum(String userCode, String chatterUserCode, String modelUserCode) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("chatterUserCode", chatterUserCode);
        if (StringUtils.isNotEmpty(userCode)) {
            params.put("userCode", userCode);
        }
        if (StringUtils.isNotEmpty(modelUserCode)) {
            params.put("modelUserCode", modelUserCode);
        }

        return this.getSqlSession().selectList(this.getStatement("queryUnReadNum"), params);
    }

    @Override
    public List<UserConversationCustomerEntity> queryChatterChatList(String chatterUserCode, String modelUserCode, String nickName, Integer sessionSaveFlag, Integer pageNum, Integer pageSize) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("chatterUserCode", chatterUserCode);
        params.put("modelUserCode", modelUserCode);
        if (Objects.nonNull(sessionSaveFlag)) {
            params.put("sessionSaveFlag", sessionSaveFlag);
        }
        if (StringUtils.isNotEmpty(nickName)) {
            params.put("nickName", nickName);
        }
        params.put("pageStart", (pageNum - 1) * pageSize);
        params.put("pageSize", pageSize);
        return this.getSqlSession().selectList(this.getStatement("queryChatterChatList"), params);
    }
}